<?php

return function ($oRes, $db_fadm) {
    $aWhere = array();
    $aWhere['visible'] = 0;
    $aWhere['status'] = 0;
    $aWhere['menu_type'] = array('M', 'C');
    $oSql = $db_fadm->sql()->table('system_menu')->where($aWhere);
    $oSql->order('parent_id,order_num');
    $aRows = $oSql->select();
    $aData = array();
    foreach ($aRows as $mRow) {
        $menu_id = $mRow['menu_id'];
        if (!isset($aData[$menu_id])) {
            $aData[$menu_id] = array();
        }
        $parent_id = $mRow['parent_id'];
        if (!isset($aData[$parent_id])) {
            $aData[$parent_id] = array();
        }
        $mMenu = array();
        $mMenu['name'] = ucfirst($mRow['path']);
        $mMenu['hidden'] = false;
        $mMenu['alwaysShow'] = ($mRow['path'] === 'M');
        $mMenu['path'] = $mRow['path'];
        if ($parent_id == 0) {
            $mMenu['path'] = '/' . $mMenu['path'];
        }
        $mMenu['component'] = $mRow['component'];
        $mMenu['meta'] = array('title' => $mRow['menu_name'], 'icon' => $mRow['icon']);
        $mMenu['children'] = &$aData[$menu_id];
        $aData[$parent_id][] = $mMenu;
    }
    $oRes->data('accessedRoutes', $aData[0]);
    $oRes->data('permissions', array('*:*:*'));
    $oRes->data('roles', array('admin'));
    $user = array();
    $user['avatar'] = '';
    $oRes->data('user', $user);
    $oRes->data('chatserver', '');
};
